using System.Text;

namespace Acme.ELeMe.SDK.Tools;

public static class Common
{
    /// <summary>
    ///     ASCII码递增排序
    /// </summary>
    /// <param name="paramsMap"></param>
    /// <returns></returns>
    public static string SortParamsByAscll(IDictionary<string, string> paramsMap)
    {
        var vDic = from objDic in paramsMap orderby objDic.Key select objDic;
        var str = new StringBuilder();
        foreach (KeyValuePair<string, string> kv in vDic)
        {
            str.Append(kv.Key + "=" + kv.Value + "&");
        }

        return str.ToString().TrimEnd('&');
    }

    // public static string GetNeedSignStr(object NeedSignObj, string SignKey, string[] ExcludeFields)
    // {
    //     var dics = NeedSignObj.ToDictionary<string>();
    //
    //     return GetNeedSignStr(dics, SignKey, ExcludeFields);
    // }

    public static string GetNeedSignStr(IDictionary<string, string> dics, string SignKey, string[] ExcludeFields)
    {
        foreach (var Key in ExcludeFields)
        {
            dics.Remove(Key);
        }

        var dicParams = SortParamsByAscll(dics);

        var NeedSignStr = dicParams + SignKey;

        return NeedSignStr;
    }
}